Daten aus Query lesen

Hier erfahren Sie, wie Sie mittels Funktionsbaustein auf die Daten eines Queries zugreifen können.

Um Daten aus einem Query zu lesen, können Sie den Funktionsbaustein RRW3_GET_QUERY_VIEW_DATA verwenden. Dieser kann remote aufgerufen werden.

Sie müssen den Infoprovider und den Querynamen übergeben sowie notwendige Selektionsparameter (Select-Options, Intervalle oder Parameter).

Der Infoprovider wird automatisch eingbelndet, wenn Sie in Transaktion RSRT den Quernamen eingeben.

Bei der Übergabe der Parameter müssen Sie den technischen Namen der Variablen verwenden.

Die technischen Namen stehen in der Tabelle GT_TEXT_SYMB, wenn Sie den Baustein einmal aufrufen. Es gibt jeweils eine Zeile für den Namen (VARIABLE_xyz) und eine für den Wert (VARVALUE_xyz).

TIPP:
Der Funktionsbaustein UMK_BW_QUERY_VIEW_DATA ruft den gleichen Baustein auf, wandelt aber das Ergebnis in XML um.

Beschreibung

Das folgende Coding ruft eine Query im entfernten BW-System auf und gibt die Daten in einer Liste aus. Zudem werden die Daten in einer internen Tabelle gesammelt und erneut ausgegeben.

Falls der Query mehr als sechs Spalten hat, müssen Sie den Typen TY_BWDATA anpassen. Theoretisch könnte die erforderliche Tabelle auch dynamisch generiert werden.

Coding 

REPORT  zz_call_bw_query LINE-SIZE 1000.

DATA gv_dest            TYPE rfcdest VALUE ‘BW_REMOTE’.
DATA gt_para            TYPE rrxw3tquery.
DATA gs_para            TYPE w3query.

DATA gt_axis_info       TYPE rrws_thx_axis_info.
DATA gt_cell_data       TYPE rrws_t_cell.
DATA gt_axis_data       TYPE rrws_thx_axis_data.
DATA gs_axis_x          TYPE rrws_sx_axis_data.
DATA gs_axis_y          TYPE rrws_sx_axis_data.
DATA gt_text_symb       TYPE rrws_t_text_symbols.

DATA gs_var             TYPE rrx_var.

DATA lv_index           TYPE i.
DATA lv_exit            TYPE c.
DATA lv_field           TYPE numc2.

FIELD-SYMBOLS <value>   TYPE ANY.
FIELD-SYMBOLS <setx>    TYPE rrws_sx_tuple.
FIELD-SYMBOLS <sety>    TYPE rrws_sx_tuple.
FIELD-SYMBOLS <cell>    TYPE rrws_s_cell.

*** define structure having maximum of six columns
TYPES: BEGIN OF ty_bwdata,
         name           TYPE text80,
         01             TYPE f,
         02             TYPE f,
         03             TYPE f,
         04             TYPE f,
         05             TYPE f,
         06             TYPE f,
         unit           TYPE meins,
         currency       TYPE waers,
       END OF ty_bwdata.

DATA gt_bwdata          TYPE STANDARD TABLE OF ty_bwdata.
FIELD-SYMBOLS <bwdata>  TYPE ty_bwdata.


START-OF-SELECTION.

*** Set must-have parameters
  CLEAR gs_para.
  gs_para-name   = ‘VAR_NAME_1’.
  gs_para-value  = ‘SDATE’.
  APPEND gs_para TO gt_para.
  gs_para-name   = ‘VAR_SIGN_1’.
  gs_para-value  = ‘I’.
  APPEND gs_para TO gt_para.
  gs_para-name   = ‘VAR_OPERATOR_1’.
  gs_para-value  = ‘BT’.
  APPEND gs_para TO gt_para.
  gs_para-name   = ‘VAR_VALUE_LOW_EXT_1’.
  gs_para-value  = ‘04.2008’.
  APPEND gs_para TO gt_para.
  gs_para-name   = ‘VAR_VALUE_HIGH_EXT_1’.
  gs_para-value  = ‘06.2008’.
  APPEND gs_para TO gt_para.

*** call query from remote bw system
  CALL FUNCTION ‘RRW3_GET_QUERY_VIEW_DATA’
    DESTINATION gv_dest
    EXPORTING
* Infoprovider Ist nicht zwingend erforderlich…
*      i_infoprovider          = ‘L_MMOG88’ “
      i_query                 = ‘Z_MY_QUERY’
      i_t_parameter           = gt_para
    IMPORTING
      e_axis_info             = gt_axis_info
      e_cell_data             = gt_cell_data
      e_axis_data             = gt_axis_data
      e_txt_symbols           = gt_text_symb
    EXCEPTIONS
      no_applicable_data      = 1
      invalid_variable_values = 2
      no_authority            = 3
      abort                   = 4
      invalid_input           = 5
      invalid_view            = 6
      OTHERS                  = 7.
  IF sy-subrc <> 0.
    WRITE: / ‘RRW3_GET_QUERY_VIEW_DATA fehler’, sy-subrc.
  ELSE.
*** Read columns
    READ TABLE gt_axis_data INTO gs_axis_x WITH KEY axis = 0.
*** Read rows
    READ TABLE gt_axis_data INTO gs_axis_y WITH KEY axis = 1.

*** print column Titles
    POSITION 74.
    LOOP AT gs_axis_x-set ASSIGNING <setx>.
      WRITE: <setx>-caption(30).
    ENDLOOP.

    CLEAR lv_index.

*** For each row….
    LOOP AT gs_axis_y-set ASSIGNING <sety>.
*** write values name
      WRITE: / <sety>-caption.
      APPEND INITIAL LINE TO gt_bwdata ASSIGNING <bwdata>.
      <bwdata>-name = <sety>-caption.
      lv_field = 1.
*** …process all columns
      LOOP AT gs_axis_x-set ASSIGNING <setx>.
*** initialize counter values
        ADD 1 TO lv_index.
        ADD 1 TO lv_field.

*** get next data
        READ TABLE gt_cell_data ASSIGNING <cell> INDEX lv_index.
        IF sy-subrc = 0.
*** print value
          WRITE <cell>-formatted_value(30) RIGHT-JUSTIFIED.
*** assign column-field of internal table
          ASSIGN COMPONENT lv_field OF STRUCTURE <bwdata> TO <value>.
          IF sy-subrc = 0.
*** set value to apropriate column in internal table
            <value> = <cell>-value.
            IF lv_field = 2.
*** setting units/ currency must be done only once
              CASE <cell>-mwkz.
                WHEN ‘M’.
                  CASE <cell>-unit.
                    WHEN ‘PCS’.
                      <bwdata>-unit = ‘ST’.
                  ENDCASE.
                WHEN ‘W’.
                  <bwdata>-currency = <cell>-currency.
              ENDCASE.
            ENDIF.
          ENDIF.
        ELSE.
          lv_exit = ‘X’.
        ENDIF.
        IF lv_exit <> space. EXIT. ENDIF.
      ENDLOOP.
      IF lv_exit <> space. EXIT. ENDIF.
    ENDLOOP.
  ENDIF.


*** now print list again from internal table:
  ULINE.
  LOOP AT gt_bwdata ASSIGNING <bwdata>.
    WRITE: / <bwdata>-name.
    IF <bwdata>-unit <> space.
      WRITE <bwdata>-unit.
      WRITE <bwdata>-01 EXPONENT 0 UNIT    <bwdata>-unit      NO-ZERO.
      WRITE <bwdata>-02 EXPONENT 0 UNIT    <bwdata>-unit      NO-ZERO.
      WRITE <bwdata>-03 EXPONENT 0 UNIT    <bwdata>-unit      NO-ZERO.
      WRITE <bwdata>-04 EXPONENT 0 UNIT    <bwdata>-unit      NO-ZERO.
      WRITE <bwdata>-05 EXPONENT 0 UNIT    <bwdata>-unit      NO-ZERO.
      WRITE <bwdata>-06 EXPONENT 0 UNIT    <bwdata>-unit      NO-ZERO.
    ELSE.
      WRITE <bwdata>-currency.
      WRITE <bwdata>-01 EXPONENT 0 CURRENCY <bwdata>-currency NO-ZERO.
      WRITE <bwdata>-02 EXPONENT 0 CURRENCY <bwdata>-currency NO-ZERO.
      WRITE <bwdata>-03 EXPONENT 0 CURRENCY <bwdata>-currency NO-ZERO.
      WRITE <bwdata>-04 EXPONENT 0 CURRENCY <bwdata>-currency NO-ZERO.
      WRITE <bwdata>-05 EXPONENT 0 CURRENCY <bwdata>-currency NO-ZERO.
      WRITE <bwdata>-06 EXPONENT 0 CURRENCY <bwdata>-currency NO-ZERO.
    ENDIF.
  ENDLOOP.

 

Enno Wulff

COMMENTS

Leave a Comment